package com.wy.projectssj.dao.impl;

import com.wy.projectssj.dao.PermissionRoleDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @Author: wy
 * @Date:2019/8/30 18:20
 */
  @Repository
public class PermissionRoleDaoImpl implements PermissionRoleDao {
       @Autowired
      private JdbcTemplate jdbcTemplate;

    @Override
    public int deleteByPid(String[] ids) {

            int result=-1;
            String s="delete from role_permission where 1=1 and permissionId in(";
            StringBuilder sql=new StringBuilder(s);
            for (int i = 0; i <ids.length ; i++) {
                if(i==ids.length-1){
                    sql.append("?)");
                }else{
                    sql.append("?,");
                }
            }
            try {
                result = jdbcTemplate.update(sql.toString(), ids);
            } catch (DataAccessException e) {
            }
            return result;
        }

}
